package reznic.ga.tracker.objects;

import java.io.IOException;
import reznic.ga.tracker.utils.StringUtils;

/**
 * Mobile App / Screen Tracking<br>
 *
 * v=1 // Version.<br>
 * &tid=UA-XXXX-Y // Tracking ID / Web property / Property ID.<br>
 * &cid=555 // Anonymous Client ID.<br>
 * <br>
 * &t=appview // Appview hit type.<br>
 * &an=funTimes // App name.<br>
 * &av=4.2.0 // App version.<br>
 * <br>
 * &cd=Home // Screen name / content description.<br>
 *
 * @author Reznic Alexandru <reznic.a@gmail.com>
 */
public class TrackMobileApp {

    private String appName;
    private String appVersion;
    private String screenName;

    public TrackMobileApp() {
    }

    public void setAppName(String appName) {
        this.appName = appName;
    }

    public void setAppVersion(String appVersion) {
        this.appVersion = appVersion;
    }

    public void setScreenName(String screenName) {
        this.screenName = screenName;
    }

    public String getAppName() {
        return appName;
    }

    public String getAppVersion() {
        return appVersion;
    }

    public String getScreenName() {
        return screenName;
    }

    public String buildURL() throws IOException {
        StringBuilder buf = new StringBuilder();
        if (StringUtils.isNotBlank(appName)) {
            buf.append("&an=").append(StringUtils.getURLString(appName));
        }
        if (StringUtils.isNotBlank(appVersion)) {
            buf.append("&av=").append(StringUtils.getURLString(appVersion));
        }
        if (StringUtils.isNotBlank(screenName)) {
            buf.append("&cd=").append(StringUtils.getURLString(screenName));
        }

        return buf.toString();
    }
}
